package sdk

import (
	"encoding/json"
	"github.com/EDDYCJY/go-gin-example/pkg/setting"
	"log"
	"os"
)

var Response  interface{}

var OpenAIInstance *RequestSigner

func SetUp() {
	logger := log.New(os.Stdout, "RequestLog: ", log.Ldate|log.Ltime|log.Lshortfile)
	// 从配置文件中读取参数
	accessKeyId := setting.OpenAiSetting.AccessKeyId
	accessKeySecret := setting.OpenAiSetting.AccessKeySecret
	endpoint := setting.OpenAiSetting.Laasendpoint
	resourceOwnerAccount := setting.OpenAiSetting.ResourceOwnerAccount
	port := setting.OpenAiSetting.LaasECSport
	signer := NewRequestSigner(accessKeyId, accessKeySecret, endpoint, port, logger, resourceOwnerAccount)
	// 配置静态数据作为熔断处理的回退
	//signer.setInternalParams()
	signer.FallbackData, _ = json.Marshal(NewFallbackData())
	// 添加拦截器函数
	//对返回的结果可以进行处理拦截器
	//正常默认 为nil
	signer.Interceptor = func(response []byte) []byte {
		return response
	}
	OpenAIInstance = signer
}
